package com.example.bank.controller;

import com.example.bank.domain.Result;
import com.example.bank.exception.SystemException;
import com.example.bank.service.city.CityService;
import com.example.bank.util.OpenIdUtil;
import com.example.bank.util.ResultUtil;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author ：Leeziqiang
 * @description：TODO
 * @date ：2021/12/26 21:16
 */
@RestController
public class WXController {

    private static final Logger logger = LoggerFactory.getLogger(WXController.class);

    @Autowired
    private CityService cityService;

    @RequestMapping("/wx")
    public String getOpenId(String code) throws IOException {
        logger.info("查询openId");
        if (code == null) {
            throw new SystemException("code为空");
        }
        String openId = OpenIdUtil.getOpenId(code);
        logger.info("openId"+openId);
        return openId;
    }

    @GetMapping("/check")
    public Integer check(Integer state) {
        if (state == 1) {
            return 200;
        } else {
            return 500;
        }
    }

    @GetMapping("/city")
    public String city(String city) {
        return cityService.getCode(city);
    }
}
